package com.ruoyi.web.controller.facility;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.facility.domain.CommerceFacility;
import com.ruoyi.facility.service.ICommerceFacilityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设施用品Controller
 *
 * @author zhezhi
 * @date 2022-10-01
 */
@RestController
@RequestMapping("/commerce/facility")
public class CommerceFacilityController extends BaseController
{
    @Autowired
    private ICommerceFacilityService commerceFacilityService;

    /**
     * 查询设施用品列表
     */
    @PreAuthorize("@ss.hasPermi('commerce:facility:list')")
    @GetMapping("/list")
    @ApiOperation("查询设施用品列表")
    public TableDataInfo list(CommerceFacility commerceFacility)
    {
        startPage();
        List<CommerceFacility> list = commerceFacilityService.selectCommerceFacilityList(commerceFacility);
        return getDataTable(list);
    }

    /**
     * 导出设施用品列表
     */
    @PreAuthorize("@ss.hasPermi('commerce:facility:export')")
    @Log(title = "设施用品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出设施用品列表")
    public void export(HttpServletResponse response, CommerceFacility commerceFacility)
    {
        List<CommerceFacility> list = commerceFacilityService.selectCommerceFacilityList(commerceFacility);
        ExcelUtil<CommerceFacility> util = new ExcelUtil<CommerceFacility>(CommerceFacility.class);
        util.exportExcel(response, list, "设施用品数据");
    }

    /**
     * 获取设施用品详细信息
     */
    @PreAuthorize("@ss.hasPermi('commerce:facility:query')")
    @GetMapping(value = "/{facilityId}")
    @ApiOperation("获取设施用品详细信息")
    public AjaxResult getInfo(@PathVariable("facilityId") Long facilityId)
    {
        return AjaxResult.success(commerceFacilityService.selectCommerceFacilityByFacilityId(facilityId));
    }

    /**
     * 新增设施用品
     */
    @PreAuthorize("@ss.hasPermi('commerce:facility:add')")
    @Log(title = "设施用品", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增设施用品")
    public AjaxResult add(@RequestBody CommerceFacility commerceFacility)
    {
        return toAjax(commerceFacilityService.insertCommerceFacility(commerceFacility));
    }

    /**
     * 修改设施用品
     */
    @PreAuthorize("@ss.hasPermi('commerce:facility:edit')")
    @Log(title = "设施用品", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改设施用品")
    public AjaxResult edit(@RequestBody CommerceFacility commerceFacility)
    {
        return toAjax(commerceFacilityService.updateCommerceFacility(commerceFacility));
    }

    /**
     * 删除设施用品
     */
    @PreAuthorize("@ss.hasPermi('commerce:facility:remove')")
    @Log(title = "设施用品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{facilityIds}")
    @ApiOperation("删除设施用品")
    public AjaxResult remove(@PathVariable Long[] facilityIds)
    {
        return toAjax(commerceFacilityService.deleteCommerceFacilityByFacilityIds(facilityIds));
    }
}
